package com.rjwh.dingdong.client.mvp.model.impl;

import com.aishua.lib.task.AsResult;
import com.aishua.lib.utils.AsStrUtils;
import com.rjwh.dingdong.client.application.MyApplication;
import com.rjwh.dingdong.client.constant.LocalConstant;
import com.rjwh.dingdong.client.constant.NetConstant;
import com.rjwh.dingdong.client.mvp.BaseModel;
import com.rjwh.dingdong.client.mvp.BasePresenter;
import com.rjwh.dingdong.client.mvp.model.ICommunityPostDetailModel;
import com.rjwh.dingdong.client.network.ApiRequest;
import com.rjwh.dingdong.client.network.HttpWebService;
import com.rjwh.dingdong.client.network.HttpWebServiceCallBack;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by wby on 2016/6/1.
 */
public class CommunityPostDetailModel extends BaseModel implements ICommunityPostDetailModel, HttpWebServiceCallBack {

    public CommunityPostDetailModel(BasePresenter basePresenter) {
        super(basePresenter);
    }

    @Override
    public void doGetPostBasicData(String topicid) {

        Map<String, String> params = new HashMap<String, String>();
        params.put("userid",
                MyApplication.spUtil.getStrPreferenceByParamName(MyApplication.app, LocalConstant.SP_USERID));
        if (!AsStrUtils.isEmpty(topicid)) {
            params.put("topicid", topicid);
        }
        HttpWebService.getDataFromServer(NetConstant.COMMUNITY_GETPOSTBASICDATA, params, true, this);
    }

    @Override
    public void doCollection(String topicid, String operateid) {
        ApiRequest
                .doAddFavorOrZan(topicid, "0", "2", operateid, this);
    }

    @Override
    public void doPraise(String topicid, String operateid) {
        ApiRequest
                .doAddFavorOrZan(topicid, "0", "1", operateid, this);
    }


    @Override
    public void onServerDataAcquired(int businessType, AsResult mAsResult, boolean isRefresh) {
        if(getBasePresenter()!= null)this.getBasePresenter().onServerDataAcquired(businessType, mAsResult, isRefresh);
    }
}
